//AntTable组件的属性缓存
import storage  from '@/utils/storage'
export default {
  namespaced: true,
  state: {
    //是否显示边框单元格
    borderCell: storage.get('borderCell', true),
    //是否边框加粗
    borderBold: storage.get('borderBold', false),
    //是否居左显示
    leftDisplay: storage.get('leftDisplay', true),
    //是否支持换行
    supportLineBreak: storage.get('supportLineBreak', false),
    //是否允许拖拽排序
    dragAndSort: storage.get('dragAndSort', false),
  },
  mutations: {
    SET_BORDER_CELL(state, val) {
        state.borderCell = val
    },
    SET_LEFT_DISPLAY(state, val) {
        state.leftDisplay = val
    },
    SET_BORDER_BOLD(state, val) {
        state.borderBold = val
    },
    SET_SUPPORT_LINEBREAK(state, val) {
        state.supportLineBreak = val
    },
    SET_DRAG_AND_SORT(state, val) {
        state.dragAndSort = val
    },
  },
  actions: {
    // 浏览器设置表格属性缓存
    setTableAttr({ commit }, attr) {
        let flag = true
        const { key, val } = attr
        switch (key) {
            case 'borderCell':
                commit('SET_BORDER_CELL', val)
                break
            case 'leftDisplay':
                commit('SET_LEFT_DISPLAY', val)
                break
            case 'borderBold':
                commit('SET_BORDER_BOLD', val)
                break
            case 'supportLineBreak':
                commit('SET_SUPPORT_LINEBREAK', val)
                break
            case 'dragAndSort':
                commit('SET_DRAG_AND_SORT', val)
                break
            default:
                flag = false
                break
        }
        if (flag) {
          storage.set(key, val)
        }
    }
  }
}
